package org.theSeed.redisIntegration.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.redisson.codec.JsonJacksonCodec;
import org.theSeed.base.pojo.constant.DateConstant;

import java.text.SimpleDateFormat;

/**
 * redisson序列化器
 */
public class SeedJsonJacksonCodec extends JsonJacksonCodec {
    /**
     * json序列化mapper
     */
    public static final ObjectMapper objectMapper;

    static {
        objectMapper = new ObjectMapper();
        //null值忽略
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        //时间格式序列化
        objectMapper.setDateFormat(new SimpleDateFormat(DateConstant.DATE_TIME));
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    }

    public SeedJsonJacksonCodec() {
        super(objectMapper);
    }
}
